package com.aqie.easy.tree;

import com.aqie.easy.structure.TreeNode;

/**
 * 897 递增顺序查找树
 * 二分搜索树 中序遍历重排 每个节点只有一个右子节点
 * 中序遍历 ： 左 根 右
 * todo
 */
public class IncreasingBST {
    public TreeNode increasingBST(TreeNode root) {
        return  increasingBST(root,null);
    }
    public TreeNode increasingBST(TreeNode root,TreeNode next){
        if(root==null) return null;
        if(root.right==null) root.right = next;
        else root.right = increasingBST(root.right,next);
        if(root.left==null) return root;
        next = root;
        TreeNode ans = increasingBST(root.left,next);
        root.left = null;

        return ans;
    }


}
